<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {_list} function plugin
 *
 * Type:     function<br>
 * Name:     _list<br>
 * Date:     Oct 22, 2008<br>
 * Purpose:  <br>
 * Input:<br>
 *         - from = element data
 *         - element = element type, used for selecting template
 *         - type = out type. tr by default
 *
 * Examples:
 * <pre>
 * {_list from=$items}
 * </pre>
 * @author Alex Yaroshevich <qfox@ya.ru>
 * @version 0.1a beta
 * @link http://docs.commercial.su/view:smarty {_list}
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function__list( $params, &$smarty )
{
	if( !is_array( $params['from'] ) )
	{
		if( !isset( $params['item'] ) ) return '';
		$params['from'] = array( $params['item'] );
		unset( $params['item'] );
	}
	
	if( isset( $params['id'] ) )
		$params['__id'] = $params['id'];
	
	$validtypes = array( 'object', 'user', 'company', 'video', 'vacancy', 'article' );
	$params['__type'] = isset( $params['type'] ) && in_array( $params['type'], $validtypes ) ? $params['type'] : $validtypes[0];
	unset( $params['type'] );
	
	$smarty ->assign( $params );
	$_r = $smarty ->fetch( "bits/list.sma" );
	
	return $_r;
}

?>